# -*- coding: utf-8 -*-
'''
Created on 05/lug/2009

@author: sax
'''
from django import template
from django.template.defaultfilters import stringfilter
register = template.Library()

@register.filter(name='truncatechars')
@stringfilter
def truncatechars(value, arg):

    try:
        return value[:int(length)] + '...'
    except ValueError: 
        return value

truncatechars.is_safe = True
#register.filter('truncatechars', truncatechars)

@stringfilter
def wrappable(value):
    """
    Places zero-width breaking spaces in text to allow it to wrap at any point.
    
    Munges text into HTML, so should be used last in the filter chain.
    {{ user_generated_text|wrappable }}
    """
    return "&#8203;".join(value)
register.filter('wrappable', wrappable)
